package com.example.admin.controller;



import com.example.admin.service.SupService;
import com.example.common.result.PageBean;
import com.example.common.result.Result;
import com.example.model.supplier.dto.SupplierProductDTO;
import com.example.model.supplier.pojo.Supplier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@Slf4j
public class SupController {

    @Autowired
    private SupService supService;

    @GetMapping("/admin/sups")
    public Result page(@RequestParam(value = "page", defaultValue = "1") Integer page ,
                       @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize,
                       @RequestParam(value = "supplierName", required = false) String supplierName,
                       @RequestParam(value = "productName", required = false) String productName) {
        PageBean page1 = supService.page(page, pageSize, supplierName, productName);
        return Result.success(page1);
    }

    @DeleteMapping("/admin/sups/{ids}")
    public Result delete(@PathVariable(required = true) List<Integer> ids){
        supService.delete(ids);
        return Result.success();
    }

    @PostMapping("/admin/sups")
    public Result save(@RequestBody SupplierProductDTO supplierProductDTO){
        supService.save(supplierProductDTO);
        return Result.success();
    }
    /**
     * 更新回显
     * @param id
     * @return
     */
    @GetMapping("/admin/sups/{id}")
    public Result selectById(@PathVariable Integer id){
        SupplierProductDTO supplierProductDTO = supService.selectById(id);
        return Result.success(supplierProductDTO);
    }

    @PutMapping("/admin/sups")
    public Result updateById(@RequestBody SupplierProductDTO supplierProductDTO){
        supService.updateById(supplierProductDTO);
        return Result.success();
    }

}
